<?php

namespace app\admin\controller;

use app\common\controller\Base;
use think\facade\Request;

class Adminstore extends Base
{
    public function getStore()
    {
        // 调用模型查询数据库数据
        $param = Request::param();
        $pageSize = $param['pageSize'];
        $data = \app\admin\model\SpecGoods::paginate($pageSize);
        // 将数据返回给前台
        $this->ok($data);
    }
    //添加商品数据
    public function storeadd()
    {

        //接受数据
        $param = Request::param();
        $data = [

            'goods_name' => $param['goods_name'],
            'price' => $param['price'],
            'number' => $param['number'],
            'images' => $param['image'],
            'order_type' => $param['order_type']
        ];
        $res = \app\admin\model\SpecGoods::create($data);
        $this->ok($res);
    }
    //上传图片
    public function storeimage()
    {
        // 获取表单上传文件 例如上传了001.jpg
        $file = request()->file('logo');
        // 移动到框架应用根目录/uploads/ 目录下
        $info = $file->move('../public/uploads');
        if ($info) {
            // 成功上传后 获取上传信息

            // 输出 20160820/42a79759f284b767dfcb2a0197904287.jpg
            $data = '/uploads/' . $info->getSaveName();

            $this->ok($data);
        } else {
            // 上传失败获取错误信息
            echo $file->getError();
        }
    }
    //获取商品类型
    public function getType()

    {
        // $this->ok('111111');
        $res = \app\admin\model\Sort::select();
        $this->ok($res);
    }

    //商品修改
    public function xgadds()
    {
        $param = Request::param();

        $res = \app\admin\model\SpecGoods::where('id', $param['id'])->update([
            'goods_name' => $param['goods_name'],
            'price' => $param['price'],
            'number' => $param['number'],
        ]);
        $this->ok($res);
    }

    //商品删除
    public function storesc()
    {
        $param = Request::param();

        $res = \app\admin\model\SpecGoods::where('id', $param['id'])->delete();
        $this->ok($res);
    }
}
